#ifndef __FTP_TRANS_H__
#define __FTP_TRANS_H__

#ifdef BMFTPTRANSFER_EXPORTS
#define BMFTPTRANSFER_API _declspec(dllexport)
#else
#define BMFTPTRANSFER_API _declspec(dllimport)
#endif
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <vector>
#include "curl/curl.h"
#include <sys/stat.h>
#include <cstring>
#include "downloadHelp.h"
using namespace std;

static size_t write_data(void *buf, size_t unit, size_t bufSize, std::string *data)
{
	int size = unit * bufSize;
	char *tmp = (char *)malloc(size + 1);
	memcpy(tmp, buf, size);
	tmp[size] = '\0';
	data->append(tmp);
	free(tmp);
	return size;
}

class FtpTrans
{
public:
	FtpTrans();

	~FtpTrans();

	int login(const char *ip, const char *user, const char *pwd, long timeout);

	int logout();

	vector<const char *> enumDirectory(const char *filename);

	int upload(const char *remotepath, const char *localpath, long tries);

	int download(const char *remotepath, const char *localpath, long tries);

	int getFtpServerDir(const char *url, const char *pwd, long tries);

	int dirlist(const char *url, const char *remote, std::vector<FILE_INFO> &vecFileInfo);

private:
	// size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream);
	// size_t discardfunc(void *ptr,size_t size, size_t nmemb, void *stream);
	// size_t writefunc(void *ptr, size_t size, size_t nmemb, void *stream);
	// size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream);

	std::string userKey;
	CURL *curlhandle = NULL;
	CURL *curldwn = NULL;
	std::vector<const char *> files;
};
#endif